﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Security.Cryptography;

namespace BussControl
{
/// <summary>
/// Summary description for RegisterControl
/// </summary>
    public class RegisterControl
    {   

             private static RegisterControl instance = null;

             public static RegisterControl Instance
             {
                 get
                 {
                     if (instance == null)
                     {
                         instance = new RegisterControl();
                     }
                     return instance;
                 }
             }


	    public RegisterControl()
	    {
		//
		// TODO: Add constructor logic here
		//
	    }
        /// <summary>
        /// 輸入帳號,密碼,確認的密碼
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="Password"></param>
        /// <param name="AgainPassword"></param>
        /// <returns></returns>
        public DataTable GetLogUserData(string UserName,string Password,string AgainPassword) 
        {
            DataTable dt = new DataTable();
        
            dt = DataManager.RegisterManager.Instance.GetAllRegisterDataById(UserName.ToString().Trim(),Password.ToString().Trim());
            HttpApplicationState Application = HttpContext.Current.Application;
            
            try
            {
                 if (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Password.ToString().Trim() + dt.Rows[0]["Salt"].ToString(), "sha1") == dt.Rows[0]["Password"].ToString().Trim()||
                    System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(AgainPassword.ToString().Trim() + dt.Rows[0]["Slat"].ToString(), "sha1") == dt.Rows[0]["AgainPassword"].ToString().Trim())
                {
                       return dt;
                }
                #region 計算登入錯誤( 再設計)
                //else
                //{
                //    if (Application["LogInCounter"] == null)
                //    {
                //        Application.Add("LogInCounter", 1);
                //    }
                //    else
                //    {
                //        Application.Lock();
                //        Application.Set("LogInCounter", (int)Application["LogInCounter"] + 1);
                //        Application.UnLock();
                //        //Label lb = new Label();
                //        //lb.Text = "您已經輸入" + Application["LogInCounter"].ToString() + "次錯誤了唷!再一次就會離開此頁!";
                //        //Page.Form.Controls.Add(lb);
                //        if ((int)Application["LogInCounter"] >= 3)
                //        {
                //            //Response.Write("<script>alert('" + Application["LogInCounter"] + "')</script>");
                //            //Response.Redirect("GetPassword.aspx?LogInCounter=" + Application["LogInCounter"]);
                            
                //        }
                //    }
                //}
                #endregion

            }
            catch (Exception ex)
            {
                ex.ToString();

            }
              return null;
           }
    }



    
}